﻿using Auto_Buy.Component;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Quartz;
using Quartz.Impl;

namespace Auto_Buy
{
    class Program
    {
        static void Main(string[] args)
        {
            var cancleTokenSource = new CancellationTokenSource();
            try
            {
                //UserSession.UserInfos.Add(new UserSubInfo { Phone = "15961956476", Pwd = "654321", TradePwd = "654321" });
                //UserSession.UserInfos.Add(new UserSubInfo { Phone = "18761216965", Pwd = "654321", TradePwd = "654321" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "15961956582", Pwd = "654321", TradePwd = "654321" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "18014691671", Pwd = "654321", TradePwd = "654321" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "15365705890", Pwd = "654321", TradePwd = "654321" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13677952871", Pwd = "456456", TradePwd = "456456" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13775813642", Pwd = "456789", TradePwd = "456789" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13618171201", Pwd = "456789", TradePwd = "456789" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13775811145", Pwd = "456789", TradePwd = "456789" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "15601696308", Pwd = "456789", TradePwd = "456789" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13585652082", Pwd = "456789", TradePwd = "456789" });
                UserSession.UserInfos.Add(new UserSubInfo { Phone = "13585589659", Pwd = "456789", TradePwd = "456789" });

                foreach (var u in UserSession.UserInfos)
                {
                    u.CoverPhone = u.Phone.Substring(0, 3) + "****" + u.Phone.Substring(7, 4);
                    //Console.WriteLine($"{u.Phone}\t {u.CoverPhone}");
                }
            
                
                var scheduler = StdSchedulerFactory.GetDefaultScheduler(cancleTokenSource.Token).Result;
                scheduler.Start();
                var job = JobBuilder.Create<AutoBuyJob>().WithIdentity("AutoBuyJob", "Auto").Build();
                var trigger = TriggerBuilder.Create().WithIdentity("AutoBuyJobTrigger", "Auto")
                    .WithSimpleSchedule(it => it.WithIntervalInSeconds(7*60 +30).RepeatForever()).Build();

                scheduler.ScheduleJob( job, trigger);

                Console.WriteLine("doing");
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error");
                Console.WriteLine(ex.Message);
            }

           

            Console.ReadLine();
            cancleTokenSource.Cancel();
            Console.WriteLine("OVER");

        }
    }
}
